﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dzs.Web.Admin.mp
{
    public partial class mylist : Web.Admin.BasePage
    {
        Maticsoft.BLL.monthSupplayPlan bll = new Maticsoft.BLL.monthSupplayPlan();        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["login"] != null)
                {
                    BLL.configinfo bc = new BLL.configinfo();
                    Model.configinfo c = bc.GetModel();
                    lblmsg.Text = "配送月开始日期为：" + c.psyqs.Value.ToString() + "，配送月结束日期为：" + c.psyjs.Value.ToString();
                    BindData();
                }
                Page.DataBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }        

        #region gridView

        public void BindData()
        {
            
            int id = getid();
            DataSet ds = new DataSet();
            StringBuilder strWhere = new StringBuilder();
            strWhere.Append(" and user_id=" + id);
            if (txtKeyword.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and material like '%{0}%'", txtKeyword.Text.Trim());
            }
            if (txtKeyword2.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and projectname like '%{0}%'", txtKeyword2.Text.Trim());
            }
            if (txtKeyword3.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and sname like '%{0}%'", txtKeyword3.Text.Trim());
            }
            strWhere.Append(" order by sname");
            ds = bll.GetListnums(strWhere.ToString());
            gridView.DataSource = ds;
            gridView.DataBind();
        }

        protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridView.PageIndex = e.NewPageIndex;
            BindData();
        }
        protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //#warning 代码生成警告：请检查确认真实主键的名称和类型是否正确
            //int ID = (int)gridView.DataKeys[e.RowIndex].Value;
            //bll.Delete(ID);
            //gridView.OnBind();
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < gridView.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)gridView.Rows[i].FindControl("DeleteThis");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (gridView.DataKeys[i].Value != null)
                    {
                        idlist += gridView.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }
        #endregion       
    }
}